
uniform sampler2D sBaseMap; 

varying vec3 vNormal;
varying vec3 vViewVec;
varying vec3 vLightVec;
varying vec2 vTexCoord;

void main()
{
	// Fetch basemap color
	vec4 baseColor = texture2D( sBaseMap, vTexCoord );
	
	vec3 normal = normalize(vNormal);
	vec3 lightDirection = normalize( vLightVec );
	vec3 viewDirection = normalize( vViewVec );

	// Compute N.L                                                           
	float nDotL = dot( normal, lightDirection );

	// Compute reflection vector
	vec3 reflection = ( 2.0 * normal * nDotL ) - lightDirection;

	// Compute R.V
	float rDotV = max( 0.0, dot( reflection, viewDirection ) );

	// Compute Ambient term
	vec4 ambient = vec4(0.368,0.368,0.368,1.0) * baseColor;

	// Compute Diffuse term
	vec4 diffuse = vec4(0.885,0.885,0.885,1.0) * nDotL * baseColor;

	// Compute Specular term
	vec4 specular = vec4(0.488,0.488,0.488,1.0) * pow( rDotV, 25.0 );

	// Output final color
	gl_FragColor = ambient + diffuse + specular;
}

